home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Networking / AFP C++ / TestSession.cp < prev    next >
Encoding:
Text File  |  1992-05-01  |  2.6 KB  |  135 lines  |  [TEXT/MPS ]

  1. /************************************************************************
  2.  
  3. Created: Monday, Sept 23, 1991
  4.     TestSession.cp
  5.     An inherited AFPSession class so that we can print buffers, errors etc. in MPW
  6.     M.Vierling
  7.  
  8.  
  9.         Copyright Apple Computer, Inc. 1991 - 1992
  10.         All rights reserved
  11.  
  12. ************************************************************************/
  13. #include <CType.h>
  14. #include <Stream.h>
  15. #include <stdlib.h>
  16. #include <Memory.h>
  17. #include <Resources.h>
  18. #include <Strings.h>
  19. #include <errors.h>
  20. #include "TestSession.h"
  21.  
  22.  
  23. void TestSession::SetPrint( Boolean printflag )
  24. {
  25.     fPrintFlag = printflag;
  26. }
  27.  
  28. void TestSession::SetPrintReply( Boolean printflag )
  29. {
  30.     if (printflag)
  31.     {
  32.         this->SetPrint( true );
  33.     }
  34.     fPrintReply = printflag;
  35. }
  36.  
  37. void TestSession::Debug( OSErr theErr, const char * message )
  38. {
  39.     if (fPrintFlag)
  40.     {
  41.         if (theErr != 0)
  42.             cout << message << theErr << "\n";
  43.         else
  44.             cout << message << "\n";
  45.     }
  46. }
  47.  
  48. void TestSession::PrintBuffer( Ptr Buffer, int BufferSize )
  49. {
  50.     unsigned short * b;
  51.     Ptr x;
  52.     
  53.     if (!fPrintFlag)
  54.         return;
  55.     cout << "hex dump: ";
  56.     
  57.     b = (unsigned short *)Buffer;
  58.     for ( int i = 0; i < BufferSize; i += 2 )
  59.     {
  60.         cout.width(4);
  61.         cout.fill('0');
  62.         cout << hex << *b << " ";
  63.         b++;
  64.     };
  65.  
  66.     cout << dec << "\n";
  67.  
  68.     cout << "str dump: ";
  69.     x = Buffer;
  70.     for ( int j = 0; j < BufferSize; j++ )
  71.     {
  72.         if isgraph( *x )
  73.             cout << *x;
  74.         else
  75.             cout << '.';
  76.         x++;
  77.     };
  78.     cout << endl;
  79. }
  80.  
  81. void TestSession::SetFileName( char * theName )
  82. {
  83.     fSourceFileName = theName;
  84. }
  85.  
  86. void TestSession::CheckErr( OSErr expectedError, int linenumber )
  87. {
  88.     if (expectedError != fErrResult)
  89.     {
  90.         cerr << "File \"" << fSourceFileName << "\"; "
  91.              << "line " << linenumber << " ### Error = " << fErrResult;
  92.         if (expectedError != 0)
  93.             cerr << " Expected error = " << expectedError << endl;
  94.         else
  95.             cerr << "\n";
  96.     }
  97. }
  98.  
  99. OSErr TestSession::DoAFPCommand( XPPParmBlkPtr theParamPtr )
  100. {
  101.     Ptr Buffer;
  102.     int BufferSize;
  103.     
  104.     Buffer = theParamPtr->XPP.cbPtr;
  105.     BufferSize = theParamPtr->XPP.cbSize;
  106.     this->PrintBuffer( Buffer, BufferSize );
  107.     
  108.     TAFPSession::DoAFPCommand( theParamPtr );
  109.  
  110.     if (fPrintReply)
  111.     {
  112.         Buffer = theParamPtr->XPP.rbPtr;
  113.         BufferSize = theParamPtr->XPP.rbSize;
  114.         this->PrintBuffer( Buffer, BufferSize );
  115.     }
  116.  
  117.     return fErrResult;
  118. }
  119.  
  120. OSErr TestSession::ISession( char * zoneName, char * serverName )
  121. {
  122.     AddrBlock theAddress;
  123.     
  124.     theAddress = FindServer( zoneName, serverName );
  125.     if ((theAddress.aNet == 0) && (theAddress.aNode == 0) && (theAddress.aSocket == 0))
  126.     {
  127.         cerr << "LLPT: NBP lookup failed for " << serverName << "\n";
  128.         exit(1);
  129.     }
  130.     TAFPSession::ISession( theAddress );
  131.     this->SetPathDelimiter( '@' );
  132.     return fErrResult;
  133. }
  134.  
  135.